﻿using System;
using System.Collections.Generic;
using CI.Interfaces;
using CI.Organism;

namespace CI.Misc
{
#pragma warning disable 1591

    /// <summary>
    /// Emulate hosting environment
    /// </summary>
    public class MockHostingEnvironmentPhysical : IHostingEnvironmentPhysical
    {
        readonly Dictionary<IOrganism, ILocation> _location = new Dictionary<IOrganism, ILocation>();

        #region IHostingEnvironmentPhysical Members

        public ILocation GetLocation(IOrganism organism)
        {
            return _location[organism];
        }

        public ILocation SetLocation(IOrganism organism, ILocation location)
        {

            // remove it if is their
            if (_location.ContainsKey(organism))
                _location.Remove(organism);

            // add the new value
            _location.Add(organism, location);
            organism.Location = location;

            return _location[organism];
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        // just return all okay
        public bool RegisterCell(ICell cell, ActionType actionType)
        {
            switch (actionType)
            {
                case ActionType.AddCell:
                    _location.Add(cell.Organism, cell.Organism.Location);
                    break;

                case ActionType.RemoveCell:
                    _location.Remove(cell.Organism);
                    break;
            }

            return true;
        }

        #endregion


        #region IHostingEnvironmentPhysical Members

        #endregion

        #region IHostingEnvironmentPhysical Members


        public bool Registered(IOrganism organism)
        {
            return _location.ContainsKey(organism);
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public Dictionary<Guid, IPhysicalEnvironment> Entitys
        {
            get { throw new NotImplementedException(); }
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public void CleanUp()
        {
            throw new NotImplementedException();
        }

        #endregion

        public void WaitForIdle()
        {
            return;
        }

        #region IHostingEnvironmentPhysical Members


        public void SanityCheck()
        {
            return;
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public int MaxEntitysSupported
        {
            get { return int.MaxValue; }
        }

        public int EntitysConsumed
        {
            get { return _location.Count; }
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public void Break()
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public void HideExternalCameraWindow(bool hide)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IHostingEnvironmentPhysical Members


        public int EntitysTolerence
        {
            get { throw new NotImplementedException(); }
        }

        #endregion


        public System.Windows.Controls.UserControl DisplayControl
        {
            get { throw new NotImplementedException(); }
        }


        public void ShutDownService()
        {
            throw new NotImplementedException();
        }

        #region IHostingEnvironmentPhysical Members


        public void BindSynapseIO(IOrganism organism)
        {
            return;
        }

        public void UnBindSynapseIO(IOrganism organism)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    /// <summary>
    /// Emulate fitness function
    /// </summary>
    public class MockFitnessFunction : IFitnessFunction
    {
        #region IFitnessFunction Members

        public void UpdateOrganisms(IOrganismCollection organisms)
        {
            return;
        }

        public List<IOrganism> Fittest(IOrganismCollection organisms)
        {
            foreach (IOrganism organism in organisms)
            {
                organism.FitnessValue = organism.InitCIET;
            }
            return new List<IOrganism>(organisms);
        }

        public long EvaluateFitnessAndUpdateInternalFitnessValue(IOrganism organism)
        {
            return 0;
        }

        #endregion
    }

    /// <summary>
    /// Emulate the simulation restrictions
    /// </summary>
    public class MockSimulation : ISimulationRestrictions
    {
        #region ISimulation Members

        public void RestrictionChecking(IHostingEnvironment hostingEnvironment)
        {
            return;
        }

        public void FitnessChecking(IOrganism organism)
        {
            return;
        }

        #endregion
    }
}


